﻿namespace ExamV5.Persion
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class ShowDayRubricInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected CheckBoxList CBLBData;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Image ImgOKAnswerS;
        protected Label labID;
        protected Label labOKAnswer;
        protected Label labOKMemo;
        protected Label labOpertion;
        protected Label labRubricTitle;
        protected Label labType;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLAData;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (this.publicFun_0.GetValues("select ID from DayRecored where UserCode='" + this.httpCookie_0.Value + "' and Convert(varchar(10),InputTime,120)=Convert(varchar(10),getdate(),120)", "ID") != "")
            {
                base.Response.Write("<script>alert('每日一题您今日已做答,请明日再来，谢谢！')</script>");
            }
            else
            {
                string str;
                string str4 = "N";
                string str2 = "";
                string strSql = "";
                if (this.RBLAData.Visible)
                {
                    if (this.RBLAData.SelectedIndex < 0)
                    {
                        base.Response.Write("<script>alert('请选择相关答案！')</script>");
                        return;
                    }
                    if (this.RBLAData.SelectedItem.Value == this.labOKAnswer.Text.Trim())
                    {
                        str4 = "Y";
                        str2 = "正确";
                        this.ImgOKAnswerS.Visible = true;
                        this.ImgOKAnswerS.ImageUrl = "../image/WriteY.gif";
                    }
                    else
                    {
                        str4 = "N";
                        str2 = "错误";
                        this.ImgOKAnswerS.Visible = true;
                        this.ImgOKAnswerS.ImageUrl = "../image/WriteN.gif";
                        this.labOKAnswer.Visible = true;
                        this.labOKAnswer.Text = "<br><br><font color=red>正确答案：</font>" + this.labOKAnswer.Text.Trim().Replace("#", "、").Replace("Y", "正确").Replace("N", "错误");
                        if (this.labOKMemo.Text.Trim() != "")
                        {
                            this.labOKMemo.Visible = true;
                            this.labOKMemo.Text = "<br><font color=red>答案说明：</font>" + this.labOKMemo.Text;
                        }
                    }
                    strSql = "insert into DayRecored(RubricID,IsOK,UserCode,UserName) values('" + this.labID.Text.Trim() + "','" + str2 + "','" + this.httpCookie_0.Value + "','" + this.httpCookie_1.Value + "')";
                    this.publicFun_0.ExecuteSql(strSql);
                    this.butDefault.Visible = false;
                    if (str4 == "Y")
                    {
                        str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='DayFen'", "ParmValue").Trim();
                        if (str.Trim() == "")
                        {
                            str = "1";
                        }
                        this.publicFun_0.ExecuteSql("insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('" + this.httpCookie_0.Value + "','解答每日一题试题','" + str + "','JoinDay','0','T')");
                    }
                }
                if (this.CBLBData.Visible)
                {
                    string str5 = "";
                    for (int i = 0; i < this.CBLBData.Items.Count; i++)
                    {
                        if (this.CBLBData.Items[i].Selected)
                        {
                            switch (i)
                            {
                                case 0:
                                    str5 = str5 + "A#";
                                    break;

                                case 1:
                                    str5 = str5 + "B#";
                                    break;

                                case 2:
                                    str5 = str5 + "C#";
                                    break;

                                case 3:
                                    str5 = str5 + "D#";
                                    break;

                                case 4:
                                    str5 = str5 + "E#";
                                    break;

                                case 5:
                                    str5 = str5 + "F#";
                                    break;
                            }
                        }
                    }
                    if (str5.Length <= 1)
                    {
                        base.Response.Write("<script>alert('请选择相关答案！')</script>");
                    }
                    else
                    {
                        if (!(str5.Substring(0, str5.Length - 1) == this.labOKAnswer.Text.Trim()))
                        {
                            str4 = "N";
                            str2 = "错误";
                            this.ImgOKAnswerS.Visible = true;
                            this.ImgOKAnswerS.ImageUrl = "../image/WriteN.gif";
                            this.labOKAnswer.Visible = true;
                            this.labOKAnswer.Text = "<br><br><font color=red>正确答案：</font>" + this.labOKAnswer.Text.Trim().Replace("#", "、").Replace("Y", "正确").Replace("N", "错误");
                            if (this.labOKMemo.Text.Trim() != "")
                            {
                                this.labOKMemo.Visible = true;
                                this.labOKMemo.Text = "<br><font color=red>答案说明：</font>" + this.labOKMemo.Text;
                            }
                        }
                        else
                        {
                            str4 = "Y";
                            str2 = "正确";
                            this.ImgOKAnswerS.Visible = true;
                            this.ImgOKAnswerS.ImageUrl = "../image/WriteY.gif";
                        }
                        strSql = "insert into DayRecored(RubricID,IsOK,UserCode,UserName) values('" + this.labID.Text.Trim() + "','" + str2 + "','" + this.httpCookie_0.Value + "','" + this.httpCookie_1.Value + "')";
                        this.publicFun_0.ExecuteSql(strSql);
                        this.butDefault.Visible = false;
                        if (str4 == "Y")
                        {
                            str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='DayFen'", "ParmValue").Trim();
                            if (str.Trim() == "")
                            {
                                str = "1";
                            }
                            this.publicFun_0.ExecuteSql("insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('" + this.httpCookie_0.Value + "','解答每日一题试题','" + str + "','JoinDay','0','T')");
                        }
                    }
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "--每日一题";
                    string str2 = "";
                    string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
                    Random random = new Random();
                    SqlConnection selectConnection = new SqlConnection(connectionString);
                    DataSet dataSet = new DataSet();
                    string values = this.publicFun_0.GetValues("select DISTINCT RubricID from DayRecored where UserCode='" + this.httpCookie_0.Value + "'");
                    if (values.Length > 1)
                    {
                        values = values.Substring(0, values.Length - 1);
                    }
                    string selectCommandText = "select a.ID from RubricInfo a,SubjectInfo b where a.RubricType in('A','B','C') and a.ISCheck='N' and a.IsDel='N' and a.Flag='E' and a.SubjectId=b.ID ";
                    selectCommandText = selectCommandText + " and (b.BrowUserCode like '%,所有人员,%' or b.BrowUserCode like '%," + this.httpCookie_0.Value + ",%'  or b.BrowDeptID like '%," + this.httpCookie_3.Value + ",%' or b.BrowDeptName like '%,所有部门,%' )";
                    if (values.Length > 1)
                    {
                        selectCommandText = selectCommandText + " and a.ID not in(" + values + ")";
                    }
                    new SqlDataAdapter(selectCommandText, selectConnection).Fill(dataSet, "AExamData");
                    int count = dataSet.Tables["AExamData"].Rows.Count;
                    if (count != 0)
                    {
                        int num2 = random.Next(count);
                        str2 = dataSet.Tables["AExamData"].Rows[num2]["ID"].ToString();
                    }
                    else
                    {
                        str2 = "0";
                    }
                    SqlConnection connection = new SqlConnection(connectionString);
                    connection.Open();
                    SqlCommand command = new SqlCommand("select ID,RubricType,RubricTitle,OptionAnswer,OKAnswer,OKMemo from RubricInfo where ID=" + str2, connection);
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    if (!reader.Read())
                    {
                        base.Response.Write("<script>alert('暂无每日一题试题库！')</script>");
                    }
                    else
                    {
                        string[] strArray;
                        this.labOKMemo.Text = reader["OKMemo"].ToString().Trim();
                        this.labRubricTitle.Text = reader["RubricTitle"].ToString().Trim();
                        this.labID.Text = reader["ID"].ToString().Trim();
                        this.labOKAnswer.Text = reader["OKAnswer"].ToString().Trim();
                        this.labOpertion.Text = reader["OptionAnswer"].ToString().Trim();
                        if (reader["RubricType"].ToString().Trim() != "A")
                        {
                            if (reader["RubricType"].ToString().Trim() == "B")
                            {
                                this.RBLAData.Visible = false;
                                this.CBLBData.Visible = true;
                                this.CBLBData.Items.Clear();
                                strArray = reader["OptionAnswer"].ToString().Trim().Split(new char[] { '#' });
                                if (strArray[0].Trim() != "")
                                {
                                    strArray[0] = "A、" + strArray[0];
                                    this.CBLBData.Items.Add(strArray[0]);
                                }
                                if (strArray[1].Trim() != "")
                                {
                                    strArray[1] = "B、" + strArray[1];
                                    this.CBLBData.Items.Add(strArray[1]);
                                }
                                if (strArray[2].Trim() != "")
                                {
                                    strArray[2] = "C、" + strArray[2];
                                    this.CBLBData.Items.Add(strArray[2]);
                                }
                                if (strArray[3].Trim() != "")
                                {
                                    strArray[3] = "D、" + strArray[3];
                                    this.CBLBData.Items.Add(strArray[3]);
                                }
                                if (strArray[4].Trim() != "")
                                {
                                    strArray[4] = "E、" + strArray[4];
                                    this.CBLBData.Items.Add(strArray[4]);
                                }
                                if (strArray[5].Trim() != "")
                                {
                                    strArray[5] = "F、" + strArray[5];
                                    this.CBLBData.Items.Add(strArray[5]);
                                }
                            }
                            else
                            {
                                this.RBLAData.Visible = true;
                                this.CBLBData.Visible = false;
                                this.RBLAData.Items.Clear();
                                this.RBLAData.Items.Insert(0, new ListItem("正确", "Y"));
                                this.RBLAData.Items.Insert(1, new ListItem("错误", "N"));
                            }
                        }
                        else
                        {
                            this.RBLAData.Visible = true;
                            this.CBLBData.Visible = false;
                            this.RBLAData.Items.Clear();
                            strArray = reader["OptionAnswer"].ToString().Trim().Split(new char[] { '#' });
                            if (strArray[0].Trim() != "")
                            {
                                strArray[0] = "A、" + strArray[0];
                                ListItem item6 = new ListItem(strArray[0], "A");
                                this.RBLAData.Items.Insert(0, item6);
                            }
                            if (strArray[1].Trim() != "")
                            {
                                strArray[1] = "B、" + strArray[1];
                                ListItem item5 = new ListItem(strArray[1], "B");
                                this.RBLAData.Items.Insert(1, item5);
                            }
                            if (strArray[2].Trim() != "")
                            {
                                strArray[2] = "C、" + strArray[2];
                                ListItem item4 = new ListItem(strArray[2], "C");
                                this.RBLAData.Items.Insert(2, item4);
                            }
                            if (strArray[3].Trim() != "")
                            {
                                strArray[3] = "D、" + strArray[3];
                                ListItem item3 = new ListItem(strArray[3], "D");
                                this.RBLAData.Items.Insert(3, item3);
                            }
                            if (strArray[4].Trim() != "")
                            {
                                strArray[4] = "E、" + strArray[4];
                                ListItem item2 = new ListItem(strArray[4], "E");
                                this.RBLAData.Items.Insert(4, item2);
                            }
                            if (strArray[5].Trim() != "")
                            {
                                strArray[5] = "F、" + strArray[5];
                                ListItem item = new ListItem(strArray[5], "F");
                                this.RBLAData.Items.Insert(5, item);
                            }
                        }
                    }
                    reader.Close();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

